package org.sao.security.core.social;

import javax.sql.DataSource;

import org.sao.security.core.properties.SecurityProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.crypto.encrypt.Encryptors;
import org.springframework.social.config.annotation.EnableSocial;
import org.springframework.social.config.annotation.SocialConfigurerAdapter;
import org.springframework.social.connect.ConnectionFactoryLocator;
import org.springframework.social.connect.UsersConnectionRepository;
import org.springframework.social.connect.jdbc.JdbcUsersConnectionRepository;
import org.springframework.social.security.SpringSocialConfigurer;

@Configuration
@EnableSocial
public class SocialConfig extends SocialConfigurerAdapter {

	@Autowired
	DataSource dataSource;
	@Autowired
	SecurityProperties securityProperties;

	@Override
	public UsersConnectionRepository getUsersConnectionRepository(
			ConnectionFactoryLocator connectionFactoryLocator) {
		// TODO Auto-generated method stub
		return new JdbcUsersConnectionRepository(dataSource,
				connectionFactoryLocator, Encryptors.noOpText());
	}
	
	@Bean
	public SpringSocialConfigurer zySocialSecurityConfig(){
		String filterProcessUrl = securityProperties.getSocial().getFilterProcessesUrl();
		ZySpringSocialConfigurer zs =new ZySpringSocialConfigurer(filterProcessUrl);
		return zs;
	}

}
